<?php
	$dsn = "mysql:host=127.0.0.1;dbname=c1";
	try{
		$pdo = new Pdo($dsn,"root","");
		$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
	}catch(PDOException $e){
		die($e->getMessage());
	}
	$pdo->query("SET NAMES utf8");
	//准备一条SQL
	//绑定参数
	//发送请求
	try{
		$sql  ="INSERT INTO  news(title,content) values(:title,:content)";
		$stmt = $pdo->prepare($sql);
		$data = array(
				array("title"=>"标题1","content"=>"正文1"),
				array("title"=>"标题2","content"=>"正文2"),
				array("title"=>"标题3","content"=>"正文3"),
				array("title"=>"标题4","content"=>"正文4"),
				array("title"=>"标题5","content"=>"正文5"),
		);
		foreach($data as $d){
			$stmt->execute(array(":title"=>$d['title'],":content"=>$d['content']));
		}
		// if($affected = $stmt->execute()){
		// 	echo "插入成功";
		// }
	}catch(PDOException $e){
		echo $e->getMessage();
	}
?>